var express = require('express');
var router = express.Router();
var pool = require('../db')

console.log(pool);

/* GET users listing. */
router.get('/', function(req, res, next) {
  // nodemon实时更新
  res.send('123456');
});
// 登录接口
router.post('/login',function(req,res,next){
  // post传参 req.body
  // get传参  req.query
  console.log(req.body);
  const { userName,passWord } = req.body

  //查询数据 pool.query
  //带条件进行查询
  pool.query(`select * from user where name='${userName}' and password='${passWord}'`,(err,data)=>{
    if(err){
      res.send({
        code:0,
        message:'sql错误'
      })
    }else{
      res.send({
        code:1,
        message:'登录成功'
      })
    }
  })

  res.send('我是登录接口')
})
module.exports = router;
